﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BingVis.GoogleTransit.Test
{
    /// <summary>
    /// Summary description for ParseCSVTests
    /// </summary>
    [TestClass]
    public class ParseCSVTests
    {
        private string[] testContents = 
        {
            @"stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,location_type,parent_station",
            @"place-alfcl, ,Alewife Station, ,42.395428,-71.142483, ,1, ",
            @"place-andrw, ,Andrew Station, ,42.330154,-71.057655, ,1, ",
            @"place-aport, ,Airport Station, ,42.374262,-71.030395, ,1, ",
            @"place-aqucl, ,Aquarium Station, ,42.359784,-71.051652, ,1, ",
        };

        private string[] testContentsNoFieldNames = 
        {   
            @"place-alfcl, ,Alewife Station, ,42.395428,-71.142483, ,1, ",
            @"place-andrw, ,Andrew Station, ,42.330154,-71.057655, ,1, ",
            @"place-aport, ,Airport Station, ,42.374262,-71.030395, ,1, ",
            @"place-aqucl, ,Aquarium Station, ,42.359784,-71.051652, ,1, ",
        };

        public ParseCSVTests()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        [TestMethod]
        public void CSVParser_Should_Load_Files_Without_Field_Names_In_First_Row()
        {
            var testFile = new GTFSFile("blah.txt", testContentsNoFieldNames);
            CSVParser parser = new CSVParser(@"stop_id,stop_code,stop_name,stop_desc,stop_lat,stop_lon,zone_id,location_type,parent_station");

            Assert.AreEqual<int>(4, parser.ParseFile(testFile).Count);
        }

        [TestMethod]
        public void CSVParser_Should_Load_4_Lines_From_TestContents()
        {
            // Arrange
            var testFile = new GTFSFile("blah.txt", testContents);
            CSVParser parser = new CSVParser(testFile);

            // Assign

            // Assert
            Assert.AreEqual<int>(4, parser.ParseFile(testFile).Count);
        }
                
        [TestMethod]
        public void CSVLine_Should_Have_Correctly_Ordered_Column_Values_From_TestContents()
        {
            // Arrange
            var testFile = new GTFSFile("blah.txt", testContents);
            CSVParser parser = new CSVParser(testFile);

            // Assign
            var firstLine = parser.ParseFile(testFile).First();

            // Assert
            // place-alfcl, ,Alewife Station, ,42.395428,-71.142483, ,1, 
            Assert.AreEqual<string>("place-alfcl", firstLine[0]);
            Assert.AreEqual<string>("", firstLine[1]);
            Assert.AreEqual<string>("Alewife Station", firstLine[2]);
            Assert.AreEqual<string>("", firstLine[3]);
            Assert.AreEqual<string>("42.395428", firstLine[4]);
            Assert.AreEqual<string>("-71.142483", firstLine[5]);
            Assert.AreEqual<string>("", firstLine[6]);
            Assert.AreEqual<string>("1", firstLine[7]);
            Assert.AreEqual<string>("", firstLine[8]);

        }
    }
}
